var form;
var fileId = null;
var vm = new Vue({
    el : "#KnittingNee",
    data : {
        record:{},
        sels:[],
        table: null
    },
    ready: function(){
        var _self = this;
      //  this.renderTable();
        layui.use(['layer'], function(){
            layer = layui.layer;
        });
    },
    methods: {
        Rfidcf: function(val){
            var _self = this;
            var rfid = $("#RFID").val();
            if (event && (event.keyCode != 13 || !(rfid && rfid.length > 0))) {
                return;
            }
            if (rfid==null || rfid.trim() =='') {
                alert("请先扫描RFID！");
                return;
            }   
            var data ={
                rfid:rfid
            };
            this.$nextTick(function() {
                this.$http.post(host +"KnittingNee/beginlist",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        if(res.body.results == 'false'){
                            _self.vueAlert(res.body.msg);
                            return;
                        }
                        _self.vueAlert("操作成功！");
                        this.rfidLists();
                    }else{
                        layer.msg("操作失败");
                    }
                });
            });
        },
        boxLists: function(val){
            var _self = this;
            var rfid = $("#RFID").val();

            if (rfid==null || rfid.trim() =='') {
                alert("请先扫描RFID！");
                return;
            }
            var data ={
                rfid:rfid
            };
            this.$nextTick(function() {
                this.$http.post(host +"KnittingNee/beginlist",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        if(res.body.results == 'false'){
                            _self.vueAlert(res.body.msg);
                            return;
                        }
                        _self.vueAlert("操作成功！");
                        this.rfidLists();
                    }else{
                        layer.msg("操作失败");
                    }
                });
            });
        },
        suspendLists: function(val){
            var _self = this;
            var rfid = $("#RFID").val();
            if (rfid==null || rfid.trim() =='') {
                alert("请先扫描RFID！");
                return;
            }
            var data ={
                rfid:rfid
            };
            this.$nextTick(function() {
                this.$http.post(host +"KnittingNee/suspendLists",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        if(res.body.results == 'false'){
                            _self.vueAlert(res.body.msg);
                            return;
                        }
                        _self.vueAlert("操作成功！");
                        this.rfidLists();
                    }else{
                        layer.msg("操作失败");
                    }
                });
            });
        },
        rfidLists: function(event){

            var _self = this;
            var rfid = document.getElementById("RFID").value;   //作业工单RFID
            if (event && (event.keyCode != 13 || !(rfid && rfid.length > 0))) {
                return;
            }
            form = layui.form;
            var data ={
                rfid : rfid
            };
            var ExeList = [];
            _self.$nextTick(function() {
                _self.$http.post(host +"KnittingNee/rfidLists",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        layui.use(['form'], function(){

                        _self.ExeLists = res.body.ExeLists;

                        ExeList =  _self.ExeLists;
                        if(ExeList == null){
                            _self.vueAlert("RFID不存在!!");
                            return;
                        }
                        if(ExeList[0].ZYCODE != null && ExeList[0].ZYCODE !=''){
                            document.getElementById("jobCode").innerText="工单号："+ExeList[0].ZYCODE;
                        }
                        if(ExeList[0].PRODUCT != null && ExeList[0].PRODUCT !=''){
                            document.getElementById("productName").innerText="型体："+ExeList[0].PRODUCT;
                        }
                        if(ExeList[0].YSNAME != null && ExeList[0].YSNAME !=''){
                            document.getElementById("colorName").innerText="颜色："+ExeList[0].YSNAME;
                        }
                        if(ExeList[0].TIMES != null && ExeList[0].TIMES !=''){
                            document.getElementById("inTime").innerText="下单时间："+ExeList[0].TIMES;
                        }
                        if(ExeList[0].CMCODE != null && ExeList[0].CMCODE !=''){
                            document.getElementById("size").innerText="尺码："+ExeList[0].CMCODE;
                        }
                        /*if(ExeList[0].YHNAME != null && ExeList[0].YHNAME !=''){
                            document.getElementById("manName").innerText="当前工序："+ExeList[0].YHNAME;
                        }*/

                            var ListHtml = "";

                            for( i = 0 ; i<ExeList.length ; i++){
                                if(i % 3 == 0 || i == 0){
                                    ListHtml += "<div class=\"layui-row layui-col-space15\" >";
                                }
                                if(ExeList[i].EQNAME == null){
                                    ExeList[i].EQNAME ="";
                                }if(ExeList[i].REMARK == null){
                                    ExeList[i].REMARK ="";
                                }
                                ListHtml += "<div class=\"layui-col-md4\" >";
                                if(ExeList[i].MXSTATUS == 'START'){
                                    ListHtml += "<div class=\"layui-card\" style=\"background-color: #339933; font-size:18px;\">";
                                   // ListHtml +="<h1  style=\"color : #000000; \">"+(i+1)+"</h1>";
                                    ListHtml += "<div class=\"layui-card-header\"  style=\"background-color: #339933; color : #FFFFFF; font-size:30px; \"  >"+(i+1)+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+ExeList[i].GXNAME+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["+ExeList[i].EQNAME+"]"+"</div>";
                                    ListHtml += "<div class=\"layui-card-body\"  style=\"background-color: #339933; color : #FFFFFF; \">";
                                }else if(ExeList[i].MXSTATUS == 'FINISHED'){
                                    ListHtml += "<div class=\"layui-card\" style=\"background-color: #99CCFF; font-size:18px;\">";
                                  //  ListHtml +="<h1  style=\"color : #000000; \">"+(i+1)+"</h1>";
                                    ListHtml += "<div class=\"layui-card-header\"  style=\"background-color: #99CCFF; color : #FFFFFF;font-size:30px; \"  >"+(i+1)+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+"</h1>"+ExeList[i].GXNAME+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["+ExeList[i].EQNAME+"]"+"</div>";
                                    ListHtml += "<div class=\"layui-card-body\"  style=\"background-color: #99CCFF; color : #FFFFFF; \">";
                                }else if(ExeList[i].MXSTATUS == 'STOP'){
                                    ListHtml += "<div class=\"layui-card\" style=\"background-color: #CC3333; font-size:18px;\">";
                                  //  ListHtml +="<h1  style=\"color : #000000; \">"+(i+1)+"</h1>";
                                    ListHtml += "<div class=\"layui-card-header\"  style=\"background-color: #CC3333; color : #FFFFFF;font-size:30px; \"  >"+(i+1)+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+"</h1>"+ExeList[i].GXNAME+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["+ExeList[i].EQNAME+"]"+"</div>";
                                    ListHtml += "<div class=\"layui-card-body\"  style=\"background-color: #CC3333; color : #FFFFFF; \">";
                                }else{
                                    ListHtml += "<div class=\"layui-card\" style=\"background-color: #CCCCCC; font-size:18px; \">";
                                   // ListHtml +="<h1  style=\"color : #000000; \">"+(i+1)+"</h1>";
                                    ListHtml += "<div class=\"layui-card-header\"  style=\"background-color: #CCCCCC; color : #FFFFFF;font-size:30px; \"  >"+(i+1)+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+ExeList[i].GXNAME+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["+ExeList[i].EQNAME+"]"+"</div>";
                                    ListHtml += "<div class=\"layui-card-body\"  style=\"background-color: #CCCCCC; color : #FFFFFF; \">";
                                }


                                ListHtml += ""+ExeList[i].REMARK+"";
                                ListHtml += "</div>";
                                ListHtml += "</div>";
                                ListHtml += "</div>";




                            }
                            $("#lastresultId").html(ListHtml);

                            layui.use(['form'], function(){
                                form = layui.form;
                                form.render(); //这个很重要
                            });



                        if(res.body.results == 'true'){
                            _self.vueAlert(res.body.msg);
                            return;
                        }
                        });
                    }
                });
            });

        },
        reset:function(data){
            window.location.reload();
        },
        vueAlert:function(msg){
            layui.use(['form'], function(){
                var layer = layui.layer;
                layer.msg(msg,{icon:6,time:2000});
            });
        },
        // 根据作业工单号及工序号确认作业指导书
        selectBook: function(val){
            var _self = this;
            var rfid = $("#RFID").val();
            if (rfid==null || rfid.trim() =='') {
                alert("请先扫描RFID！");
                return;
            }
            var data ={
                rfid:rfid
            };
            this.$nextTick(function() {
                this.$http.post(host +"KnittingNee/selectZyBook",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        if(res.body.results == 'false'){
                            _self.vueAlert(res.body.msg);
                            return;
                        }

                        fileId = res.body.fileId;
                        if (fileId) {
                            $("#sopBtnDiy").show();
                            openSop();
                        } else {
                            $("#sopBtnDiy").hide();
                        }
                    }else{
                        layer.msg("操作失败");
                    }
                });
            });
        },
        // // 显示指导文件
        // showDocument: function() {
        //     layer.open({
        //         type: 2,
        //         title: '工艺指导文件',
        //         shadeClose: true,
        //         shade: 0.8,
        //         area: ['90%', '90%'],
        //         content: "../../script/js/pdfJs/web/viewer.html?file=../../../../manNeedleCart/downFile/" + this.order //iframe的url
        //     });
        // },
        // 异常上报
        abnormalReport: function() {
            layer.open({
                type: 2,
                title: '异常上报',
                shadeClose: true,
                shade: 0.8,
                area: ['90%', '90%'],
                content: "abnormalReport.html" //iframe的url
            });
        }

    }
});
//打开工艺作业指导书
function openSop() {
    if (fileId) {
        top.layer.open({
            type: 2,
            title: "作业指导书",
            shadeClose: true,
            shade: 0.6,
            area: ['80%', '80%'],
            fixed:true,
            content: host + 'file?id=' + fileId,
            end:function(){
            }
        });
    }
}